import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import ParentView from '@/components/ParentView';

/**
 * Note: 路由配置项
 *
 * hidden: true                   // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true               // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect           // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'             // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * meta : {
    noCache: true                // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'               // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'             // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false            // 如果设置为false，则不会在breadcrumb面包屑中显示
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: (resolve) => require(['@/views/redirect'], resolve)
      }
    ]
  },
  {
    path: '/login',
    component: (resolve) => require(['@/views/login'], resolve),
    hidden: true
  },
  {
    path: '/404',
    component: (resolve) => require(['@/views/error/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: (resolve) => require(['@/views/error/401'], resolve),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: (resolve) => require(['@/views/index'], resolve),
        name: '首页',
        meta: {title: '首页', icon: 'user-group', noCache: true, affix: true}
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: (resolve) => require(['@/views/system/user/profile/index'], resolve),
        name: 'Profile',
        meta: {title: '个人中心', icon: 'user'}
      }
    ]
  },
  {
    path: '/dict',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'type/data/:dictId(\\d+)',
        component: (resolve) => require(['@/views/system/dict/data'], resolve),
        name: 'Data1',
        meta: {title: '字典数据', icon: ''}
      }
    ]
  },
  {
    path: '/analysis',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'populationStatistics/index',
        component: (resolve) => require(['@/views/analysis/populationStatistics/index'], resolve),
        name: 'populationStatistics',
        meta: {title: '人数统计', icon: ''}
      }
    ]
  },
  {
    path: '/base',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'template/index',
        component: (resolve) => require(['@/views/base/template/index'], resolve),
        name: 'template',
        meta: {title: '模板上传', icon: ''}
      }
    ]
  },
  {
    path: '/insurancemanagement',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'dataUpload',
        component: (resolve) => require(['@/views/insurancemanagement/uploadPersonnelList/dataUpload'], resolve),
        name: 'dataUpload',
        meta: {title: '上传人员清单', icon: ''}
      },
      {
        path: 'uploadPersonnelList/index',
        component: (resolve) => require(['@/views/insurancemanagement/uploadPersonnelList/index'], resolve),
        name: 'uploadPersonnelList',
        meta: {title: '上传人员清单', icon: ''}
      },
      {
        path: 'detailsPersons',
        component: (resolve) => require(['@/views/insurancemanagement/auditorList/detailsPersons'], resolve),
        name: 'detailsPersons',
        meta: {title: '人员清单', icon: ''}
      },
      {
        path: 'ListApplication',
        component: (resolve) => require(['@/views/insurancemanagement/ListApplication/index'], resolve),
        name: 'ListApplication',
        meta: {title: '投保单列表', icon: ''}
      },
      {
        path: 'MessageNotification',
        component: (resolve) => require(['@/views/insurancemanagement/MessageNotification/index'], resolve),
        name: 'MessageNotification',
        meta: {title: '消息通信', icon: ''}
      },
      {
        path: 'EndorsementPage/index',
        component: (resolve) => require(['@/views/insurancemanagement/EndorsementPage/index'], resolve),
        name: 'EndorsementPage',
        meta: {title: '批单人员', icon: ''}
      },
      {
        path: 'insure/index',
        component: (resolve) => require(['@/views/insurancemanagement/insure/index'], resolve),
        name: 'insure',
        meta: {title: '投保信息', icon: ''}
      },
      {
        path: 'ListApplication/details',
        component: (resolve) => require(['@/views/insurancemanagement/ListApplication/details'], resolve),
        name: 'details',
        meta: {title: '保单详情', icon: ''}
      }
    ]
  },
  {
    path: '/product',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'productType/index',
        component: (resolve) => require(['@/views/insurance/productType/index'], resolve),
        name: 'productType',
        meta: {title: '产品方案', icon: ''}
      },
      {
        path: 'type/data',
        component: (resolve) => require(['@/views/insurance/productType/data'], resolve),
        name: 'Data',
        meta: {title: '产品方案', icon: ''}
      },

    ]
  },
  {
    path: '/business',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'guarantee/index',
        component: (resolve) => require(['@/views/insurance/guarantee/index'], resolve),
        name: 'guarantee',
        meta: {title: '在保证明', icon: ''}
      },
      {
        path: 'user/index',
        component: (resolve) => require(['@/views/insurance/user/index'], resolve),
        name: 'user',
        meta: {title: '人员列表', icon: ''}
      },
      {
        path: 'OnlineReporting/index',
        component: (resolve) => require(['@/views/insurance/OnlineReporting/index'], resolve),
        name: 'OnlineReporting',
        meta: {title: '在线报案', icon: ''}
      },
      {
        path: 'user/userAdd',
        component: (resolve) => require(['@/views/insurance/user/userAdd'], resolve),
        name: 'userAdd',
        meta: {title: '投保用户添加', icon: ''}
      },
      {
        path: 'repordRecord/index',
        component: (resolve) => require(['@/views/insurance/repordRecord/index'], resolve),
        name: 'repordRecord',
        meta: {title: '报案记录', icon: ''}
      },
      {
        path: 'approve/index',
        component: (resolve) => require(['@/views/insurance/approve/index'], resolve),
        name: 'approve',
        meta: {title: '批单管理', icon: ''}
      },
      {
        path: 'applicationFiling/index',
        component: (resolve) => require(['@/views/insurance/applicationFiling/index'], resolve),
        name: 'applicationFiling',
        meta: {title: '报案申请', icon: ''}
      },
      {
        path: 'applicationFiling/applicationAdd',
        component: (resolve) => require(['@/views/insurance/applicationFiling/applicationAdd'], resolve),
        name: 'applicationAdd',
        meta: {title: '报案申请添加', icon: ''}
      },
      {
        path: 'repordRecord/repordImage',
        component: (resolve) => require(['@/views/insurance/repordRecord/repordImage'], resolve),
        name: 'repordImage',
        meta: {title: '添加报案资料', icon: ''}
      },
      {
        path: 'successfully/index',
        component: (resolve) => require(['@/views/insurance/successfully/index'], resolve),
        name: 'successfully',
        meta: {title: '报案成功', icon: ''}
      },
      {
        path: 'reportAudit/details',
        component: (resolve) => require(['@/views/insurance/reportAudit/details'], resolve),
        name: 'details',
        meta: {title: '报案详情', icon: ''}
      },
      {
        path: 'lossAmount/index',
        component: (resolve) => require(['@/views/insurance/lossAmount/index'], resolve),
        name: 'lossAmount',
        meta: {title: '核损金额', icon: ''}
      },
    ]
  },

  {
    path: '/insureEli',
    component: Layout,
    hidden: true,
    children: [
      // {
      //   path: 'index',
      //   component: (resolve) => require(['@/views/insurance/insureEli/index'], resolve),
      //   name: 'index',
      //   meta: {title: '投保管理', icon: ''}
      // },
      {
        path: 'details',
        component: (resolve) => require(['@/views/insurance/insureEli/details'], resolve),
        name: 'details',
        meta: {title: '查看详情信息', icon: ''}
      },
      {
        path: 'add',
        component: (resolve) => require(['@/views/insurance/insureEli/add'], resolve),
        name: 'add',
        meta: {title: '新增投保信息', icon: ''}
      },
      {
        path: 'edit',
        component: (resolve) => require(['@/views/insurance/insureEli/edit'], resolve),
        name: 'edit',
        meta: {title: '修改投保信息', icon: ''}
      }
    ]
  },
  {
    path: '/job',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'log',
        component: (resolve) => require(['@/views/monitor/job/log'], resolve),
        name: 'JobLog',
        meta: {title: '调度日志'}
      }
    ]
  },
  {
    path: '/gen',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'edit/:tableId(\\d+)',
        component: (resolve) => require(['@/views/tool/gen/editTable'], resolve),
        name: 'GenEdit',
        meta: {title: '修改生成配置'}
      }
    ]
  }
]

// export default new Router({
//   // mode: 'history', // 去掉url中的#
//   scrollBehavior: () => ({y: 0}),
//   routes: constantRoutes
// })

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
